<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%
id=request.QueryString("edit")
if id<>"" then
	  set rsm=server.CreateObject("adodb.recordset")
	  sql="select * from usertype where id="&id&""
	  rsm.open sql,conn,1,3
	  if not rsm.eof then
          title=rsm("title")
		  StartTotalspending=rsm("StartTotalspending")
		  EndTotalspending=rsm("EndTotalspending")
		  rate=rsm("rate")
	  rsm.close
	  set rsm=nothing
	  end if
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="main">
  <div class="main-title">会员分级</div>
  <div class="main-content">
  <%if id<>"" then%>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6">
    <form name="form" method="post" action="">
    级别名称<input name="title" type="text" class="input" id="title" value="<%=title%>" maxlength="50" />
    起始消费总额<input name="StartTotalspending" type="text" class="input" style="width:50px" value="<%=StartTotalspending%>" maxlength="50" />
    最大消费总额<input name="EndTotalspending" type="text" class="input" style="width:50px" value="<%=EndTotalspending%>" maxlength="50" />
    奖励积分比率<input name="rate" type="text" class="input" value="<%=rate%>" style="width:50px" maxlength="50" />%
    <input name="id" type="hidden" id="id" value="<%=id%>" />
<input type="submit" name="button" id="button" value="保存" />
    </form>
    </td>
    </tr>
    </table>
  <%else%>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6">
    <form name="form" method="post" action="">
    级别名称<input name="title" type="text" class="input" id="title" value="级别名称" maxlength="50" />
    起始消费总额<input name="StartTotalspending" type="text" class="input" style="width:50px" value="0" maxlength="50" />
    最大消费总额<input name="EndTotalspending" type="text" class="input" style="width:50px" value="0" maxlength="50" />
    奖励积分比率<input name="rate" type="text" class="input" value="0" style="width:50px" maxlength="50" />%
    <input type="submit" name="button" id="button" value="添加" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td bgcolor="#FFFFFF"><strong>分级名称</strong></td>
    <td align="center" bgcolor="#FFFFFF">起始消费总额</td>
    <td align="center" bgcolor="#FFFFFF">最大消费总额</td>
    <td align="center" bgcolor="#FFFFFF">奖励积分比率</td>
    <td align="center" bgcolor="#FFFFFF"><strong>操作</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>删除</strong></td>
    </tr>
     <%
					  set rsu=server.CreateObject("adodb.recordset")
					  sql="select * from usertype "
					  rsu.open sql,conn,1,3
					  if not rsu.eof then
					  do while not rsu.eof
					  %>
  <tr>
    <td bgcolor="#FFFFFF"><%=rsu("title")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rsu("StartTotalspending")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rsu("EndTotalspending")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rsu("RATE")%></td>
    <td align="center" bgcolor="#FFFFFF"><a href="?edit=<%=rsu("id")%>">修改</a></td>
    <td align="center" bgcolor="#FFFFFF"><a href="?del=<%=rsu("id")%>">删除</a></td>
    </tr>
    <%
					  rsu.movenext
					  loop
					  rsu.close
					  set rsu=nothing
					  end if		 
					  %>
  
  </table>
  <%end if%>
</div>
</div>
</body>
</html>
<%
if request.Form("button")="添加" then

	title=request.Form("title")
	StartTotalspending=request.Form("StartTotalspending")
	EndTotalspending=request.Form("EndTotalspending")
	rate=request.Form("rate")
    
	if title="" or StartTotalspending="" or EndTotalspending="" or rate="" then
	response.write"<script>alert('全部不能为空');</script>"
	response.write"<script>window.history.back(-1);</script>"
	response.end
	end if
	
	
	set rsu=server.createobject("adodb.recordset")
	sql="select * from usertype"
	rsu.open sql,conn,1,3
	rsu.addnew
	rsu("title")=title
	rsu("StartTotalspending")=StartTotalspending
	rsu("EndTotalspending")=EndTotalspending
	rsu("rate")=rate
	rsu.update
	response.write"<script language=JavaScript>{window.alert('添加成功！');window.location.href='type.asp';}</script>"
	rsu.close
	set rsu=nothing
	
elseif request.Form("button")="保存" then

	title=request.Form("title")
	StartTotalspending=request.Form("StartTotalspending")
	EndTotalspending=request.Form("EndTotalspending")
	rate=request.Form("rate")

    if title="" or StartTotalspending="" or EndTotalspending="" or rate="" then
	response.write"<script>alert('全部不能为空');</script>"
	response.write"<script>window.history.back(-1);</script>"
	response.end
	end if

	set rsu=server.createobject("adodb.recordset")
	sql="select * from usertype where id="&id&""
	rsu.open sql,conn,1,3
	rsu("title")=title
	rsu("StartTotalspending")=StartTotalspending
	rsu("EndTotalspending")=EndTotalspending
	rsu("rate")=rate
	rsu.update
	response.write"<script language=JavaScript>{window.alert('保存成功！');window.location.href='type.asp';}</script>"
	rsu.close
	set rsu=nothing

elseif request.QueryString("del")<>"" then
    conn.execute("delete from usertype where id<>1 and id="&request.QueryString("del")&"")
	response.Redirect "type.asp"
end if
%>